#     im = Image.new("1", (128, 64))
from PIL import Image, ImageDraw, ImageFont


def font():
    with Image.open("t.jpg") as base:
        # make a blank image for the text, initialized to transparent text color
        txt = Image.new("1", base.size, 0)
        # get a drawing context
        d = ImageDraw.Draw(txt)
        # get a font
        fnt = ImageFont.truetype("像素体.ttf", size=20)
        # draw text
        d.text((55,20), text="弦", font=fnt, fill=1)
        txt.show()
        # txt.save("弦.jpg")


def line():
    with Image.open("t.jpg") as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.line((25,40,35,40),1) #x+10
        draw.line((35, 40,35,25), 1) #y-15
        draw.line((35, 25, 45, 25),1) #x+10
        draw.line((45, 25,45,40), 1)  # y+15
        draw.line(( 45, 40,55,40), 1)  # x+10
        draw.line(( 55, 40,55,25), 1)  # y-15
        draw.line(( 55, 25,65,25), 1)  # x+10
        draw.line(( 65,25,65,40), 1)  # y+15
        draw.line(( 65,40,75,40), 1)  # x+10
        draw.line((75,40,75,25),1) #y-15
        draw.line(( 75, 25,85,25), 1)  # x+10
        draw.line(( 85,25,85,40), 1)  # y+15
        draw.line(( 85,40,95,40), 1)  # x+10
        im.show()
        # im.save("方波.jpg")

def wave():
    with Image.open("t.jpg") as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.arc((25, 20, 35, 40), 0, 180, 1)  # 水平10，垂直20
        draw.arc((35, 20, 45, 40), 180, 0, 1)  # 水平移动10
        draw.arc((45, 20, 55, 40), 0, 180, 1)
        draw.arc((55, 20, 65, 40), 180, 0, 1)
        draw.arc((65, 20, 75, 40), 0, 180, 1)
        draw.arc((75, 20, 85, 40), 180, 0, 1)
        draw.arc((85, 20, 95, 40), 0, 180, 1)
        im.show()
        # im.save("正弦波.jpg")

def pic():
    with Image.open("t.jpg") as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.rounded_rectangle((51, 37, 76, 59),radius=10, fill=1)
        draw.rectangle((57,47,70,50),fill=0)
        draw.rounded_rectangle((52,25, 74, 37), radius=7, fill=1)
        draw.rectangle((62, 4, 65, 47), fill=0)
        draw.rectangle((61, 4, 66, 24), fill=1)
        draw.rounded_rectangle((58,33, 69,42), radius=5, fill=0)
        draw.line((58,5,69,5),1)
        draw.line((58, 7, 69, 7), 1)
        draw.line((58, 9, 69, 9), 1)
        im.show()
        # im.save("guitar.jpg")

def tri():
    with Image.open("t.jpg") as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        # draw.polygon(((25,36),(34,20),(43,36)),1)
        draw.line((25,36,34,20), 1)
        draw.line((34,20,43,36), 1)
        draw.line((43,36,53,20), 1)
        draw.line((53, 20, 62,36), 1)
        draw.line(( 62, 36,72,20), 1)
        draw.line((72, 20,81,36), 1)
        draw.line(( 81, 36,91,20), 1)
        draw.line(( 91, 20,100,36), 1)
        im.show()
        # im.save("三角波.jpg")


def main():
    # font()
    # line()
    # wave()
    # pic()
    tri()


if __name__ == '__main__':
    main()
